<template>
	<view>
		<search class="searchPage"></search>
		<swiper autoplay indicator-dots interval="3000" circular indicator-active-color	="white">
			<swiper-item v-for="(item,index) in swiperList" :key="index" >
				<navigator :url="'../../subpkg/goodsDetail/goodsDetail?goods_id=' + item.goods_id">
					<image class="swiperImg" :src="item.image_src" mode=""></image>
				</navigator>
			</swiper-item>
		</swiper>
		<view class="cate">
			<view class="cateItem" v-for="(item,index) in cateList" :key="index" @click="goPage(item)">
				<image :src="item.image_src" mode=""></image>
			</view>
		</view>
		<!-- 电梯模块 -->
		<view class="floor" v-for="(item,index) in floorList" :key="index">
			<image class="floorImg" :src="item.floor_title.image_src" mode=""></image>
			<view class="floor-img-box">
				<navigator :url="item.product_list[0].url" class="leftImg">
					<image :src="item.product_list[0].image_src" :style="{width: item.product_list[0].image_width + 'rpx'}" mode="widthFix"></image>
				</navigator>
				<view class="floorItem">
					<navigator :url="val.url" class="" v-for="(val,i) in item.product_list" :key="i" v-if="i !== 0">
						<image :src="val.image_src" mode="widthFix" :style="{width: val.image_width + 'rpx'}"></image>
					</navigator>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import badgeMixin from '../../mixins/tabbar-badge.js'
	export default {
		data() {
			return {
				swiperList: [],
				cateList: [],
				floorList: []
			};
		},
		mixins:[badgeMixin],
		onLoad() {
			this.getSwiperList()
			this.getCateList()
			this.getFloorList()
		},
		methods:{
			async getSwiperList() {
				const {data} = await uni.$http.get('/api/public/v1/home/swiperdata')
				if (data.meta.status !== 200) {
					return uni.$showMsg()
				}
				this.swiperList = data.message
				console.log(data, 'getSwiperList')
			},
			async getCateList() {
				const {data} = await uni.$http.get('/api/public/v1/home/catitems')
				if (data.meta.status !== 200) {
					return uni.$showMsg()
				}
				this.cateList = data.message
				console.log(data, 'getCateList')
			},
			async getFloorList() {
				const {data} = await uni.$http.get('/api/public/v1/home/floordata')
				if (data.meta.status !== 200) return uni.$showMsg()
				data.message.forEach(item => {
					item.product_list.forEach(val => {
						val.url = '/subpkg/goods_list/goods_list?' + val.navigator_url.split('?')[1]
					})
				})
				this.floorList = data.message
				console.log(data, 'getFloorList')
			},
			goPage(item) {
				if (item.name === '分类') {
					uni.switchTab({
						url:"../cate/cate"
					})
				}
			}
		},
		components:{
			// search: () => import('../.././components/search/search')
		}
	}
</script>

<style lang="scss">
	.searchPage {
		position: sticky;
		top: 0;
		z-index: 999;
	}
navigator {
	height: 100%;
	.swiperImg {
		width: 100%;
		height: 100%;
	}
}
.cate {
	display: flex;
	justify-content: space-between;
	padding: 0 30rpx;
	margin: 30rpx 0;
	.cateItem {
		display: flex;
		image {
			width: 128rpx;
			height: 140rpx;
		}
	}
} 
.floor {
	margin-top: 20rpx;
	navigator {
		height: auto;
	}
	.floorImg {
		height: 60rpx;
		width: 100%;
	}
	.floor-img-box {
		display: flex;
		padding: 10rpx;
		.leftImg {
			display: inline-block;
		}
		.floorItem {
			display: flex;
			flex-wrap: wrap;
			justify-content: space-around;
			image {
				width: 100%;
				height: 100%;
			}
		}
	}
	
}
</style>
